<template>
	<view class="container">
		<view class="header">
			<view class="order-top">
				<view class="top-left" >
					<image class="black" @tap="black" src="/static/images/zuo.png"></image>
					<text>{{user.nickName}}  {{user.salesmanNo}}</text>
				</view>
				<!-- s扫码 -->
				<view class="top-right-box">
					<view class="top-right-left" @tap="search">
						<image class="search" src="/static/images/search.png" mode=""></image>
						<input type="text" placeholder-class="input"  placeholder="请输入搜索词" >
						
					</view>
					<!-- 这个版本不上线 -->
				<!-- 	<view class="top-right-text" @click="skiptoSigncalc()">
						签到统计
					</view> -->
					
				</view>
				
				
				
			</view>
			<!-- 经理有 -->
			<view class="card">
				<view class="card-list" @tap="jump('已预付',1)">
					<!--  -->
					<view class="num">{{orderResume.prePayOrders}}</view>
					<view class="dec">已预付</view>
				</view>
				<!--  -->
				<view class="card-list" @tap="jump('货到付款',2)">
					<view class="num">{{orderResume.collectOrders}}</view>
					<view class="dec">货到付款</view>
				</view>
				<!--  -->
				<view class="card-list"  @tap="jump('赊账',3)">
					<view class="num">{{orderResume.onCreditOrders}}</view>
					<view class="dec">赊账中</view>
				</view>
				
				<view class="card-list"  @tap="jump('待上传凭证',4)">
					<view class="num">{{orderResume.onTransferPayOrder}}</view>
					<view class="dec">待上传凭证</view>
				</view>
			</view>
			
			<view class="table">
				<scroll-view class="scroll" scroll-x="true" show-scrollbar="false">
					<view class="table-box ">
						<view :class="'table-list '+(active==item.index?'active':'')" v-for="(item,index) in tableList" :key="index" @tap="table(item.index)">
							{{item.tableName}}
						</view>
					</view>
				</scroll-view>
				
				
			</view>
		</view>
		
		<!-- 订单列表 -->
		<!-- 订单列表 -->
		<order-list :list="orderList" :dx="dx" :isDetail="isOrder"></order-list>
		
		 
</view>
		
</template>

<script>
	const util = require("../../utils/util.js");
	//获取应用实例
	const api = require("../../config/api.js"); 
	import orderList from "../../components/orderList/orderList"; 
	
	export default {
		data() {
			return {
				tableList:[],
				active:-1,
				user:{},
				page:1,
				orderList:[],
				// 没有更多数据
				dx:false,
				orderResume:{},
				userId:'',
				isOrder:false
			}
		},
		components: {
		  orderList
		},
		onLoad(json){
			console.log(json)
			this.user = JSON.parse(json.user)
			 this.userId = this.user.userId;
			 if(json.isOrder==1){
				 this.isOrder=true
			 }
			 console.log(this.userId)
			 util.request(api.orderResume+'?userId='+this.userId,{},'GET').then(res => {
				 console.log(res)
			 	this.orderResume = res.data
			 	
			 })
			 
			 
			this.tableList =[
				{
					tableName:'全部',
					index:''
				},
				{
					tableName:'待处理',
					index:-1
				},
				{
					tableName:'待审核',
					index:1
				},
				{
					tableName:'待配送',
					index:3
				},
				{
					tableName:'待收货',
					index:4
				},
				{
					tableName:'已收货',
					index:5
				},
				{
					tableName:'已取消',
					index:6
				}
				]
			this.getOrderList();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			console.log(this.page)
		    this.getOrderList()
			
		},
		// 上拉加载
		onReachBottom(){
			uni.showNavigationBarLoading();//显示加载动画
			this.page++;
			util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
				userId: this.user.userId
			}, 'POST').then(res => {
				console.log(res)
				if(res.error==0){
					if(this.page>1){
						 if(res.data.data.length==0){
						 	if(this.page>1){
						 		uni.hideNavigationBarLoading();//关闭加载动画
								this.dx=true
							}
						}else{
							this.orderList = [...this.orderList,...res.data.data]
						}
						
					}
					uni.hideNavigationBarLoading();//关闭加载动画
				}
			})
		},
		
		methods: {
			skiptoSigncalc(){
				uni.navigateTo({
					url:"/pages/signinCalc/signinCalc?userId=" +this.userId
					
				})
			},
			jump(tit,index){
				uni.navigateTo({
					url:"/pages/paymentList/paymentList?tit="+tit+"&index="+index+'&userId='+this.userId
					
				})
			},
			table(index){
				this.active = index;
				this.dx = false;
				this.page=1;
				this.getOrderList()
			},
			search(){
				uni.navigateTo({
					url:"/pages/search/search"
				})
			},
			black(){
				uni.navigateBack()
			},
			getOrderList(){
				// 获取订单列表
				console.log(this.page)
				console.log(this.userId)
				util.request(api.businessOrderList+'?page='+this.page+'&size=20', {
					userId:this.userId,
					status:this.active
				}, 'POST').then(res => {
					console.log(res)
					if(res.error==0){
						this.orderList = res.data.data
					}
					uni.stopPullDownRefresh()
				})
			}
		}
	}
</script>

<style>
@import url('./managerSalesman.css');
</style>
